package com.qfjg.webcore.log;

import com.qfjg.webcore.GlobalContext;
import com.qfjg.webcore.log.worker.TaskQueueWorker;

public class LogAgent {
    private static TaskQueueWorker<logParam> logInfoTaskQueueWorker;
    private static TaskQueueWorker<logParam> logInfoTaskInstance()
    {
        if (logInfoTaskQueueWorker == null)
            synchronized(TaskQueueWorker.class)
            {
                logInfoTaskQueueWorker = new TaskQueueWorker<>(logParam -> {
                    try {
                        LogAgentService service= GlobalContext.context.getBean(LogAgentService.class);
                        service.saveLog(logParam.getLogInfo(),logParam.getItToken());
                    }
                    catch (Exception ex){
                        ex.printStackTrace();
                    }
                });
            }
        return logInfoTaskQueueWorker;
    }
    public static void saveLog(logParam logParam){
        logInfoTaskInstance().AddTask(logParam);
    }
}
